export default (app: any) => {
  /**
   * 显示收纳动画指令
   * @author wangyuan
   */
  app.directive('receive', {
    created(el: any, binding: any) {
      let { direction, length } = binding.value
      direction = direction || 'right'
      length = length || 5
      el.style[direction] = `-${length}rem`
    },
    mounted(el: any, binding: any) {
      let { direction } = binding.value
      direction = direction || 'right'
      el.parentNode.style.position = 'relative'
      el.style.position = 'absolute'
      el.style.transition = 'all 0.5s'
      setTimeout(() => {
        el.style[direction] = 0
      })
    },
    updated(el: any, binding: any) {
      let { direction, will, length } = binding.value
      direction = direction || 'right'
      length = length || 5
      if (will.indexOf('hide') > -1) {
        el.style[direction] = `-${length}rem`
      } else if (will.indexOf('show') > -1) {
        el.style[direction] = 0
      }
    }
  })
}
